import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:url_launcher/url_launcher.dart';

class Swipers extends StatefulWidget {
  Swipers({Key key,this.imgs,this.height}) : super(key:key);
  final List imgs;
  final int height;
  @override
  _SwipersState createState() => _SwipersState();
}

class _SwipersState extends State<Swipers> {
  List imgs;
  int height;

  @override
  void initState() {
    imgs = widget.imgs;
    height = widget.height!=null ? widget.height : 400;
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context,width: 750,height: 1334);
    return Container(
      height: ScreenUtil().setWidth(height),
      child: new Swiper(
        scrollDirection: Axis.horizontal,
        loop: true,
        index: 0,
        autoplay: true,
        autoplayDelay: 4000,
        pagination: new SwiperPagination(),
        itemBuilder: (BuildContext context,int index){
          return new Image.network(
            imgs[index],
            fit: BoxFit.cover
          );
        },
        itemCount: imgs.length,
        viewportFraction: 1,
        scale: 1,
        onTap: (index) async {
          String url = "tel:15716022393";
          if(await canLaunch(url)){
            await launch(url);
          }else{
            throw "链接错误："+url;
          }

        },
        duration: 800
      ),
    );
  }
}